
function judge(promise,delay) {
    return Promise.race([
        new Promise((resolve, reject) => {
        setTimeout(() => {
            reject(new Error('超时啦'))
        },delay)
    }),promise
    ])
}

const p = new Promise((resolve, reject) => {
    // 这里放网络请求
    setTimeout(() => {
        resolve('1')
    },1000)
})
judge(p,2000).then(res=>{
    console.log('resolve',res)
},error=>{
    console.log('error',error.message)
})
